package com.bytedance.article.a.a;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;

import com.bytedance.common.utility.collection.WeakList;
import com.bytedance.frameworks.base.mvp.Presenter;
import com.ss.android.common.app.IComponent;
import com.ss.android.common.app.LifeCycleInvoker;
import com.ss.android.common.app.LifeCycleMonitor;
import com.ss.android.common.app.UIScreenContext;
import com.ss.android.common.app.permission.PermissionsManager;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public abstract class c<P extends Presenter> extends com.bytedance.frameworks.a.c.b<P> implements IComponent, LifeCycleInvoker, UIScreenContext {
    private boolean b;
    private boolean c;
    private boolean d;
    private WeakList e = new WeakList();
    private Map f = new HashMap();

    public final void a(Map arg5) {
        if (arg5 != null && !arg5.isEmpty()) {
            Iterator v1 = arg5.entrySet().iterator();
            while (v1.hasNext()) {
                Object v0 = v1.next();
                this.f.put(((Map.Entry) v0).getKey(), ((Map.Entry) v0).getValue());
            }
        }
    }

    public boolean isActive() {
        return this.b;
    }

    public boolean isDestroyed() {
        return this.d;
    }

    public boolean isViewValid() {
        return this.c;
    }

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.b = false;
        this.c = false;
        this.d = false;
    }

    public void onDestroy() {
        super.onDestroy();
        this.c = false;
        this.d = true;
        if (!this.e.weakHashMap.isEmpty()) {
            Iterator v1 = this.e.iterator();
            while (v1.hasNext()) {
                Object v0 = v1.next();
                if (v0 == null) {
                    continue;
                }

                ((LifeCycleMonitor) v0).onDestroy();
            }

            this.e.weakHashMap.clear();
        }
    }

    public void onDestroyView() {
        super.onDestroyView();
        this.c = false;
    }

    public void onPause() {
        super.onPause();
        this.b = false;
        if (!this.e.weakHashMap.isEmpty()) {
            Iterator v1 = this.e.iterator();
            while (v1.hasNext()) {
                Object v0 = v1.next();
                if (v0 == null) {
                    continue;
                }

                ((LifeCycleMonitor) v0).onPause();
            }
        }
    }

    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        PermissionsManager.getInstance().notifyPermissionsChange(this.getActivity(), permissions, grantResults, false);
    }

    public void onResume() {
        super.onResume();
        this.b = true;
        if (!this.e.weakHashMap.isEmpty()) {
            Iterator v1 = this.e.iterator();
            while (v1.hasNext()) {
                Object v0 = v1.next();
                if (v0 == null) {
                    continue;
                }
                ((LifeCycleMonitor) v0).onResume();
            }
        }
    }

    public void onSaveInstanceState(Bundle outState) {
        if (outState != null) {
            outState.putBoolean("WORKAROUND_FOR_BUG_19917_KEY", true);
        }

        super.onSaveInstanceState(outState);
    }

    public void onStop() {
        super.onStop();
        this.b = false;
        if (!this.e.weakHashMap.isEmpty()) {
            Iterator v1 = this.e.iterator();
            while (v1.hasNext()) {
                Object v0 = v1.next();
                if (v0 == null) {
                    continue;
                }

                ((LifeCycleMonitor) v0).onStop();
            }
        }
    }

    public void onViewCreated(View arg2, Bundle arg3) {
        super.onViewCreated(arg2, arg3);
        this.c = true;
    }

    public void registerLifeCycleMonitor(LifeCycleMonitor arg2) {
        this.e.add(arg2);
    }

    public void setEnterContext(Map map) {
        if (map != null) {
            map.isEmpty();
        }
    }

    public void setUserVisibleHint(boolean arg1) {
        super.setUserVisibleHint(arg1);
    }

    public void unregisterLifeCycleMonitor(LifeCycleMonitor arg2) {
        this.e.remove(arg2);
    }
}

